package gov.pbc.nn.kjgl.task.view;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.export.interceptor.IDataInterceptor;

import gov.pbc.nn.uflo.entity.Opinion;

@Component("interceptorExcle")
public class InterceptorExcle implements IDataInterceptor{
	
	@Autowired
	private TaskPR taskPR;
	
	@Override
	public String getDesc() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "interceptorExcle";
	}

	@Override
	public void interceptAutoFormData(List<Map<String, Object>> arg0) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void interceptGridData(List<Map<String, Object>> list) throws Exception {
		List<Map<String, Object>> exportList = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> row = new HashMap<String, Object>();
			exportList.add(row);
			String id = (String) map.get("id");
			String name = (String) map.get("name");
			Date startDate=(Date) map.get("startDate");
			Date overDate=(Date) map.get("overDate");
			String remark=(String) map.get("remark");
			row.put("name",name);
			row.put("startDate", startDate);
			row.put("overDate", overDate);
			row.put("remark", remark);
			Collection<Opinion>  taskEntity =taskPR.getOpinions(id);
			for (Opinion opinion : taskEntity) {
				Map<String, Object> row2 = new HashMap<String, Object>();
				exportList.add(row2);
//				row2.put("startDate", startDate);
//				row2.put("overDate", overDate);
//				row2.put("remark", remark);
				row2.put("deptName", opinion.getDeptName());
				row2.put("cname", opinion.getCname());
				row2.put("opinion", opinion.getOpinion());
				row2.put("createDate", opinion.getCreateDate());
			}
			
			row = new HashMap<String, Object>();
			exportList.add(row);
		}
		list.clear();
		list.addAll(exportList);
	}
}
